import React from 'react'
import {Switch,Redirect,Route} from 'react-router-dom'
export default function Index(props) {
    const {routes}=props
    const normalRoutes=routes.filter(item=>!item.to)
    const redirectRoutes=routes.filter(item=>item.to).map((item,key)=><Redirect key={key} from={item.from} to={item.to}></Redirect>)
    return (
        <Switch>
                {
                    normalRoutes&&normalRoutes.map((item,key)=><Route key={key} path={item.path}
                    render={props=><item.component {...props} routes={item.children}></item.component>}></Route>).concat(redirectRoutes)
                }
        </Switch>
    )
}
